package written_test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zhx
 * @since 2020-09-05
 */
public class Sogou {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * 返回能交换奖品的最大数量
     *
     * @param a int整型
     * @param b int整型
     * @param c int整型
     * @return int整型
     */
    public static int numberofprize(int a, int b, int c) {
        // write code here
        int min = Math.min(a, Math.min(b, c));
        int number = min;
        boolean flag = false;
        int[] abc = new int[3];
        abc[0] = a - min;
        abc[1] = b - min;
        abc[2] = c - min;
        //升序
        Arrays.sort(abc);
        while (Arrays.stream(abc).sum() >= 4 || flag) {
            Arrays.sort(abc);
            if (abc[0] > 0) {
                number += abc[0];
                abc[0] -= abc[0];
                abc[1] -= abc[0];
                abc[2] -= abc[0];
                flag = false;
            } else {
                if (abc[2] - abc[0] >= 2) {
                    if (abc[2] - abc[1] > 1) {
                        int tmp = (abc[2] - abc[1]) / 2;
                        abc[0] += tmp;
                        abc[2] -= 2 * tmp;
                    } else {
                        if (abc[1] - abc[0] <= 1) {
                            int tmp = abc[2] /3 ;
                            abc[0] += tmp;
                            abc[1] += tmp;
                            abc[2] -= 4*tmp;
                        } else {
                            int tmp = abc[2] / 2;
                            abc[0] += tmp;
                            abc[2] -= 2 * tmp;
                            abc[1] -= 2 * tmp;
                        }
                    }
                } else {
                    abc[2] -= 1;
                    abc[1] -= 1;
                    abc[0] += 1;
                }
                flag = true;
            }

        }
        return number;
    }

    /**
     * 1
     *
     * @param t
     * @param xa
     * @return
     */
    public static int getHouses(int t, int[] xa) {
        // write code here
        int result = 2;
        List<Float> intervals = new ArrayList<>();
        for (int i = 0; i < xa.length - 2; i += 2) {
            float interval = (xa[i + 2] - xa[i]) - (xa[i + 1] + xa[i + 3]) / 2;
            intervals.add(interval);
        }
        for (int i = 0; i < intervals.size(); i++) {
            if (t < intervals.get(i)) {
                result += 2;
            }
            if (t == intervals.get(i)) {
                result++;
            }
        }
        return result;
    }


    public static void main(String[] args) {
        long l = System.currentTimeMillis();
        System.out.println(numberofprize(777777777, 888888888, 999988888));
        System.out.println(numberofprize(4, 4, 2)); // 3
        System.out.println(numberofprize(9, 3, 3)); // 4
        System.out.println((System.currentTimeMillis() - l) / 1000);
//        System.out.println(getHouses(2,new int[]{-1,4,5,2}));
    }
}
